<%@page import="custom.Activity"%>
<%@page import="custom.Quiz"%>
<%@page import="custom.Performances"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Quiz "<%= request.getParameter("name") %>" summary page</title>
</head>
<script type="text/javascript">
	function toggle(id, link) {
		var e = document.getElementById(id);

		if (e.style.display == '') {
			e.style.display = 'none';
			link.innerHTML = 'Expand';
		} else {
			e.style.display = '';
			link.innerHTML = 'Collapse';
		}
	}
</script>
<body>
	<%@ include file="header.jsp" %>
	<%
		Quiz qz = Quiz.getInstance(request.getParameter("name"));
		User us = (User) session.getAttribute("user");
	%>
	<center><div style="width: 800px;" align="left">
		<div style="float: left; width: 69%; border-right:2px solid rgb(200,200,200); border-top:2px solid rgb(200,200,200); margin-right: 0.5%;" align="left">
			<div style="margin: 8px">
				<h1>"<%= qz.getName() %>"</h1>
				<p><%= qz.getDesc() %></p>
				<p>Author: <%= User.getNameHtml(qz.getAuthor() )%></p>
				<form action="QuizStartPushedServlet" method="post">
					<input type="hidden" name="name" value="<%=qz.getName()%>" />
					<input type="submit" value="start"/>
				</form>
				<%if(us.isOwnerOf(qz.getId())){ %>
					<form action="QuizEditPushedServlet" method="post">
						<input type="hidden" name="name" value="<%=qz.getName() %>" />
						<input type="submit" value="edit"/>
					</form>
				<%}
				if(us.isOwnerOf(qz.getId()) || us.areYouAdmin()){%>
					<form action="QuizRemovePushedServlet" method="post">
						<input type="hidden" name="id" value="<%=qz.getId() %>" />
						<input type="submit" value="remove"/>
					</form>
				<%}%>
			</div>
		</div>
		
					 
		<div style="float: left; width: 29%; border-left:2px solid rgb(200,200,200); border-top:2px solid rgb(200,200,200);" align="left">
			<div style="margin: 8px">
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
				
					<div style="font-style: italic; font-weight: 800;">My Performances</div>
					
					<div id="myPerfo" align="left" style="display:none">
						<%
							ArrayList<Performances> myPerfo = qz.getUserPerformances(us.getId());
							for(int i=0; i<myPerfo.size(); i++){
								out.print("<p>" + myPerfo.get(i).getHtml() + "</p>");
							}
							if(myPerfo.size() == 0)
								out.print("You have not taken the quiz yet");
						%>
					</div>
				
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('myPerfo', this)" >Expand</a>
					</div>
				</div>
				
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
					<div style="font-style: italic; font-weight: 800;">Top 5 Performances Ever</div>
					
					<div id="top5ever" align="left" style="display:none">
						<%
							Performances [] top5ever = qz.getTop5EverPerformances();
							int i1;
							for(i1=0; i1<top5ever.length; i1++){
								if(top5ever[i1] == null)	break;
								out.print("<p>" + top5ever[i1].getHtml() + "</p>");
							}
							if(i1 == 0)
								out.print("Noone has taken the quiz yet");
						%>
					</div>
					
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('top5ever', this)" >Expand</a>
					</div>
				</div>
				
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
					<div style="font-style: italic; font-weight: 800;">Top 5 Performances Today</div>
					<div id="top5today" align="left" style="display:none">
						<%
							Performances [] top5today = qz.getTop5TodayPerformances();
							int i2;
							for(i2=0; i2<top5today.length; i2++){
								if(top5today[i2] == null)	break;
								out.print("<p>" + top5today[i2].getHtml() + "</p>");
							}
							if(i2 == 0)
								out.print("Noone has taken the quiz yet");
						%>
					</div>
					
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('top5today', this)" >Expand</a>
					</div>
				</div>
				
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
					<div style="font-style: italic; font-weight: 800;">Last 5 Performances</div>
					<div id="last5" align="left" style="display:none">
						<%
							Performances [] last5 = qz.getLast5Performances();
							int i3;
							for(i3=0; i3<last5.length; i3++){
								if(last5[i3] == null)	break;
								out.print("<p>" + last5[i3].getHtml() + "</p>");
							}
							if(i3 == 0)
								out.print("Noone has taken the quiz yet");
						%>
					</div>
					
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('last5', this)" >Expand</a>
					</div>
				</div>
				
				
			</div>
		</div>
	</div></center>
</body>
</html>